package com.cloud.pay.job;

import com.cloud.pay.entity.PayConfig;
import com.cloud.pay.service.PayConfigService;
import com.cloud.pay.constant.PayChannelEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component
public class PayConfigJob {

    @Autowired
    private PayConfigService payConfigService;

    @Scheduled(fixedDelay = 3000)
    public void load() {
        List<PayConfig> list = payConfigService.list().stream().filter(payConfig -> payConfig.getStatus() == 1).collect(Collectors.toList());
        for (PayChannelEnum payChannelEnum : PayChannelEnum.values()) {
            payChannelEnum.getPayAdapter().loadConfig(list);
        }
    }
}
